﻿@using Eqwww.Code
@{
    ViewData["Title"] = "StrategoryManage";
    Layout = "~/Views/Shared/_ManageFormLayout.cshtml";
}

<form id="form1">
    <input type="hidden" id="RoleId" name="RoleId" />
    <div class="mdui-container">
        <div class="mdui-row">
            <div class="mdui-col-xs-12 mdui-col-sm-6 ">

                <ul class="mdui-list">

                    @{
                        var Items = (List<ListToggleModel>)ViewBag.Items;
                        foreach (var item in Items)
                        {

                            <li class="mdui-list-item mdui-ripple">

                                <div class="mdui-list-item-content">
                                    @if (!string.IsNullOrEmpty(item.Description))
                                    {
                                        <div class="mdui-list-item-title">@item.Title</div>
                                        <div class="mdui-list-item-text mdui-list-item-one-line">
                                            @item.Description
                                        </div>
                                    }
                                    else
                                    {
                                        @item.Title
                                    }
                                </div>
                                <label class="mdui-switch">
                                    <input name="strategory" type="checkbox" value="@item.Value"
                                           @if (item.Checked==true)
                                           {
                                               <text>checked</text>
                                           }
                                           @if (item.Disabled == true)
                                           {
                                               <text>disabled</text>
                                           }
                                           />
                                    <i class="mdui-switch-icon"></i>
                                </label>
                            </li>
                            <li class="mdui-divider mdui-m-y-0"></li>
                        }
                    }

                </ul>

            </div>
        </div>
    </div>
</form>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

    <script>
        var roleId = $.request('id');
        $(function () {
            $('#RoleId').val(roleId);
        });

        function submitForm() {
            if (!$("#form1").valid()) {
                return false;
            }
            var postData = $('#form1').formSerialize();

            var vals = $('input:checkbox[name="strategory"]:checked').map(function (index, elem) {
                return $(elem).val();
            }).get().join(',');
            postData['strategorys'] = vals;

            
            $.submitForm({
                url: "/SystemManage/Role/StrategoryManage",
                param: postData,
                success: function () {
                    $.currentWindow().location.reload();
                }
            });

        };
    </script>

}

